package com.Lixiaoqian.Gulangyu.utils;

import android.graphics.Color;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;

/**
 * Created by huangzhibo on 2017/10/27/027.
 * mail:1043202454@qq.com
 */

public class StatusBarUtils {

    /**
     * 全屏不隐藏状态栏(5.0)
     *
     * @param app
     */
    public static void fullSrcAndNoHideBar(AppCompatActivity app) {
        if(Build.VERSION.SDK_INT >= 21) {
            View decorView = app.getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;// | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;//全屏,状态栏字体颜色黑色
            decorView.setSystemUiVisibility(option);
            app.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
    }


    /**
     * 设置状态栏颜色(默认不占用状态栏高度)
     *
     * @param app
     * @param color 只能用系统的Color类去解析颜色,不然无效果 5.0
     */
    public static void setBarBgColor(AppCompatActivity app, int color) {
        if(Build.VERSION.SDK_INT >= 21) {
            Window window = app.getWindow();
            if(color == Color.WHITE) {  //白色  5-6 : 6 以上处理
                if(Build.VERSION.SDK_INT < 23) {
                    window.setStatusBarColor(Color.GRAY);
                }else {
                    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                    window.setStatusBarColor(Color.WHITE);
                }
            }else {
                window.setStatusBarColor(color);
            }
        }
    }


}
